package com.burstly.lib.component;

import android.os.Handler;
import com.burstly.lib.constants.Constants;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.Utils;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

public class AdaptorListener
  implements IBurstlyAdaptorListener
{
  private static final int GLOBAL_TIMEOUT = Utils.getIntValue(Constants.GLOBAL_ADAPTOR_TIMEOUT, Integer.valueOf(35000)).intValue();
  static final LoggerExt LOG = LoggerExt.getInstance();
  private String mClickRedirectUrl;
  private final AdaptorController mController;
  private boolean mForceStop;
  private boolean mHandledFullCycle;
  private final Handler mHandler;
  private boolean mShowingFailed;
  private boolean mTimedOut;
  private final Runnable mTimeout;

  AdaptorListener(final AdaptorController paramAdaptorController)
  {
    this.mController = paramAdaptorController;
    this.mHandler = new Handler();
    this.mTimeout = new Runnable()
    {
      public void run()
      {
        AdaptorController localAdaptorController = (AdaptorController)this.val$aController.get();
        if (localAdaptorController != null)
        {
          AdaptorListener.LOG.logDebug(localAdaptorController.mTag, "Adaptor request timed out!", new Object[0]);
          localAdaptorController.getAdaptor().stop();
          AdaptorListener.this.failedToLoad(localAdaptorController.getNetworkName(), paramAdaptorController.mIsInterstitial, "Request timed out!");
        }
        AdaptorListener.access$002(AdaptorListener.this, true);
      }
    };
    LoggerExt localLoggerExt = LOG;
    String str = paramAdaptorController.mTag;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Integer.valueOf(GLOBAL_TIMEOUT);
    localLoggerExt.logInfo(str, "Starting global watchdog with {0} ms timeout...", arrayOfObject);
    this.mHandler.postDelayed(this.mTimeout, GLOBAL_TIMEOUT);
  }

  private boolean preventDidLoad()
  {
    return (this.mTimedOut) || ((this.mForceStop) && (this.mHandledFullCycle));
  }

  private void stopWatching()
  {
    this.mHandler.removeCallbacks(this.mTimeout);
    LOG.logDebug(this.mController.mTag, "Released global adaptor watchdog.", new Object[0]);
  }

  public void adWasClicked(String paramString, boolean paramBoolean)
  {
    AdaptorController localAdaptorController = this.mController;
    LOG.logDebug(localAdaptorController.mTag, "Adaptor was clicked", new Object[0]);
    localAdaptorController.click();
  }

  public void didLoad(String paramString, final boolean paramBoolean)
  {
    Runnable local2 = new Runnable()
    {
      public void run()
      {
        AdaptorListener.LOG.logDebug(this.val$comp.mTag, "Adaptor did load", new Object[0]);
        if (!AdaptorListener.this.preventDidLoad())
        {
          if (!AdaptorListener.this.mHandledFullCycle)
          {
            AdaptorListener.this.stopWatching();
            this.val$comp.mIsInterstitial = paramBoolean;
            this.val$comp.handleSuccessToLoad();
            AdaptorListener.access$202(AdaptorListener.this, true);
          }
        }
        else
          return;
        this.val$comp.sendTrackShowRequest();
      }
    };
    this.mHandler.post(local2);
  }

  public void dismissedFullscreen(final IBurstlyAdaptorListener.FullscreenInfo paramFullscreenInfo)
  {
    Runnable local4 = new Runnable()
    {
      public void run()
      {
        LoggerExt localLoggerExt = AdaptorListener.LOG;
        String str = this.val$comp.mTag;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = paramFullscreenInfo;
        localLoggerExt.logDebug(str, "dismissedFullscreen for {0}", arrayOfObject);
        this.val$comp.getBursltlyAdListener().onHideFullscreen(paramFullscreenInfo);
      }
    };
    this.mHandler.post(local4);
  }

  public void failedToLoad(String paramString1, final boolean paramBoolean, final String paramString2)
  {
    Runnable local3 = new Runnable()
    {
      private void processingFailedToLoad()
      {
        if (!AdaptorListener.this.mShowingFailed)
        {
          if ((paramString2 != null) && (!paramString2.equals("")))
            AdaptorListener.LOG.logWarning(this.val$comp.mTag, paramString2, new Object[0]);
          this.val$comp.mIsInterstitial = paramBoolean;
          this.val$comp.addComponentToFailedCollector();
          this.val$comp.notifyFailed(false);
          AdaptorListener.access$502(AdaptorListener.this, true);
          return;
        }
        AdaptorListener.LOG.logWarning(this.val$comp.mTag, "Double failed callback, skipped.", new Object[0]);
      }

      public void run()
      {
        AdaptorListener.LOG.logDebug(this.val$comp.mTag, "Adaptor failed to load", new Object[0]);
        if ((!AdaptorListener.this.mTimedOut) && (!AdaptorListener.this.mForceStop))
        {
          AdaptorListener.this.stopWatching();
          processingFailedToLoad();
        }
        while (!AdaptorListener.this.mTimedOut)
          return;
        processingFailedToLoad();
      }
    };
    this.mHandler.post(local3);
  }

  void forceStop()
  {
    stopWatching();
    this.mForceStop = true;
  }

  public String getClickRedirectUrl()
  {
    return this.mClickRedirectUrl;
  }

  public void onCollapse(String paramString)
  {
    AdaptorController localAdaptorController = this.mController;
    LOG.logDebug(localAdaptorController.mTag, "Adaptor was collapsed", new Object[0]);
    localAdaptorController.getBursltlyAdListener().onCollapse();
  }

  public void onExpand(String paramString, boolean paramBoolean)
  {
    AdaptorController localAdaptorController = this.mController;
    LoggerExt localLoggerExt = LOG;
    String str = localAdaptorController.mTag;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Boolean.valueOf(paramBoolean);
    localLoggerExt.logDebug(str, "Adaptor was expanded (isFullscreen {0})", arrayOfObject);
    localAdaptorController.getBursltlyAdListener().onExpand(paramBoolean);
  }

  public void onHide(String paramString)
  {
    AdaptorController localAdaptorController = this.mController;
    LOG.logDebug(localAdaptorController.mTag, "Adaptor was hidden", new Object[0]);
    localAdaptorController.getBursltlyAdListener().onHide();
  }

  public void onShow(String paramString)
  {
    AdaptorController localAdaptorController = this.mController;
    LOG.logDebug(localAdaptorController.mTag, "Adaptor was shown", new Object[0]);
    localAdaptorController.getBursltlyAdListener().onShow();
  }

  public void setClickRedirectUrl(String paramString)
  {
    this.mClickRedirectUrl = paramString;
  }

  public void shownFullscreen(final IBurstlyAdaptorListener.FullscreenInfo paramFullscreenInfo)
  {
    Runnable local5 = new Runnable()
    {
      public void run()
      {
        LoggerExt localLoggerExt = AdaptorListener.LOG;
        String str = this.val$comp.mTag;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = paramFullscreenInfo;
        localLoggerExt.logDebug(str, "shownFullscreen for {0}", arrayOfObject);
        if ((!AdaptorListener.this.mTimedOut) && (!AdaptorListener.this.mForceStop))
          this.val$comp.getBursltlyAdListener().onShowFullscreen(paramFullscreenInfo);
      }
    };
    this.mHandler.post(local5);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.AdaptorListener
 * JD-Core Version:    0.6.2
 */